﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.Runtime.Serialization;
using System.Xml;

namespace PServiceBus.WCF.NetTcpTransport {
    public class DataSerializerOperationBehavior : DataContractSerializerOperationBehavior {
        private bool _preserveReferences = false;
        private int _maxItemsInObjectGraph = 65536;

        public DataSerializerOperationBehavior(OperationDescription operationDescription, bool preserveReferences, int maxItemsInObjectGraph)
            : base(operationDescription) {
            _preserveReferences = preserveReferences;
            _maxItemsInObjectGraph = maxItemsInObjectGraph;
        }

        public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes) {
            return new DataContractSerializer(type, name, ns, knownTypes, this.MaxItemsInObjectGraph, this.IgnoreExtensionDataObject, _preserveReferences, this.DataContractSurrogate);
        }

        public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes) {
            return new DataContractSerializer(type, name, ns, knownTypes, _maxItemsInObjectGraph, this.IgnoreExtensionDataObject, _preserveReferences, this.DataContractSurrogate);
        }
    }
}
